package com.lz.sentinel.project.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
import com.lz.sentinel.common.entity.RequestVo;
import com.lz.sentinel.common.entity.ResponseVo;
import com.lz.sentinel.common.utils.DateUtils;
import org.springframework.web.bind.annotation.*;

/**
 *  债券计算 限流
 * @author Administrator
 */
@RestController
@RequestMapping(value = "/bond")
public class CalcBondController {
    int ct = 1;
    @PostMapping("/calc")
    @SentinelResource(value = "bond", fallback = "handleFallback")
    public ResponseVo send(@RequestBody RequestVo requestVo) {
        System.out.println(DateUtils.getCurr_YYYY_MM_DD_HH_MM_SS_SSS() + "： bond calc成功");
        ct++;
        System.out.println("ct:"+ct);
        return ResponseVo.success("bond calc成功 "+ct);
    }
    public ResponseVo handleFallback(@RequestBody RequestVo requestVo) throws FlowException {
        //throw new FlowException("bond calc 目前系统请求繁忙，请稍后重试");
        return ResponseVo.failure( "bond calc 目前系统请求繁忙，请稍后重试");
    }

}